package com.beiming.libra.controller;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.beiming.libra.common.utils.HttpClientUtils;
import com.beiming.libra.domain.dto.tdhnet.requestdto.TdhnetWajjbxxRequestDTO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 南京通达海对接
 * @author lenovo
 *
 */
@RestController
@Api(value = "通达海对接", tags = "通达海对接")
@RequestMapping("/api/tdhnet")
public class TdhnetController {
	final static String HTTPURL = "http://221.226.175.76:7208/sfjk/ssfw_app/app/";
	final static String METHOD_KTGG = "ktgg";
	/**
	 * 个案基本信息列表
	 */
	final static String METHOD_WAJJBXX = "wajjbxx";
	final static String CID = "BM_TDH_PORTAL";

	@ApiOperation(value = "个案基本信息列表", notes = "个案基本信息列表")
	@PostMapping("/wajjbxx")
	public String wajjbxx(TdhnetWajjbxxRequestDTO dto) {
		Map<String, String> map = objToMap(dto);
		String result = HttpClientUtils.sendHttpPost(HTTPURL + METHOD_WAJJBXX, map);
		return result;
	}
	
	
	private static Map<String, String> objToMap(Object obj) {  
        Map<String, String> map = new HashMap<String, String>();  
        Field[] fields = obj.getClass().getDeclaredFields();  
        for (int i = 0; i < fields.length; i++) {  
            String varName = fields[i].getName();  
            try {  
                boolean accessFlag = fields[i].isAccessible();  
                fields[i].setAccessible(true);  
                Object o = fields[i].get(obj);  
                if (o != null)  {
                	map.put(varName, o.toString());  
                }
                fields[i].setAccessible(accessFlag);  
            } catch (IllegalArgumentException ex) {  
                ex.printStackTrace();  
            } catch (IllegalAccessException ex) {  
                ex.printStackTrace();  
            }  
        }  
        return map;  
    } 
}
